// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class QUERY_RESULT_CLUSTER_RSP_Q11 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 MFE",8)]
  	    [HL7Field(HL7Version.v25, 8, HL7Repeat.False, HL7Required.True,"MFE")]
	    public MFE MFE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 LOC",9)]
  	    [HL7Field(HL7Version.v25, 9, HL7Repeat.False, HL7Required.True,"LOC")]
	    public LOC LOC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("10 LCH",10)]
  	    [HL7Field(HL7Version.v25, 10, HL7Repeat.True, HL7Required.False,"LCH")]
	    public LCH[] LCH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 LRL",11)]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.True, HL7Required.False,"LRL")]
	    public LRL[] LRL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 MF_LOC_DEPT",12)]
  	    [HL7Field(HL7Version.v25, 12, HL7Repeat.True, HL7Required.True,"MF_LOC_DEPT_RSP_Q11")]
	    public MF_LOC_DEPT_RSP_Q11[] MF_LOC_DEPT {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			MFE = PopSegmentParseAndCheckRequired<MFE>(availableData, options, "MFE");
			LOC = PopSegmentParseAndCheckRequired<LOC>(availableData, options, "LOC");
			LCH = PopSegmentParseAndCheckRequiredArray<LCH>(availableData, options, "LCH");
			LRL = PopSegmentParseAndCheckRequiredArray<LRL>(availableData, options, "LRL");
			MF_LOC_DEPT = ProcessGroupArray<MF_LOC_DEPT_RSP_Q11>(availableData, options, "MF_LOC_DEPT");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isMFE = availableData.StartsWith("MFE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("MFE", options.Version) || isMFE) {
				return isMFE;
			}
			bool isLOC = availableData.StartsWith("LOC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LOC", options.Version) || isLOC) {
				return isLOC;
			}
			bool isLCH = availableData.StartsWith("LCH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LCH", options.Version) || isLCH) {
				return isLCH;
			}
			bool isLRL = availableData.StartsWith("LRL", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LRL", options.Version) || isLRL) {
				return isLRL;
			}
			MF_LOC_DEPT_RSP_Q11 testMF_LOC_DEPT_RSP_Q11 = new MF_LOC_DEPT_RSP_Q11();
			bool grpCCMF_LOC_DEPT_RSP_Q11 = (testMF_LOC_DEPT_RSP_Q11.CanConsume(availableData, options));
			if (IsRequired("MF_LOC_DEPT", options.Version) || grpCCMF_LOC_DEPT_RSP_Q11) {
				return grpCCMF_LOC_DEPT_RSP_Q11;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "QUERY_RESULT_CLUSTER";
			}
        }

        static QUERY_RESULT_CLUSTER_RSP_Q11() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(QUERY_RESULT_CLUSTER_RSP_Q11));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (MFE != null) {
			string segmentValue = MFE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (LOC != null) {
			string segmentValue = LOC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (LCH != null && LCH.Length > 0) {
			for (int i = 0; i < LCH.Length; i++) {
				string segmentValue = LCH[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (LRL != null && LRL.Length > 0) {
			for (int i = 0; i < LRL.Length; i++) {
				string segmentValue = LRL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (MF_LOC_DEPT != null && MF_LOC_DEPT.Length > 0) {
			for (int i = 0; i < MF_LOC_DEPT.Length; i++) {
				string segmentValue = MF_LOC_DEPT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

